<template>
	<view class="leave_box">
    <navTitle :titleRight="''" :title="'添加项目經歷'"></navTitle>
    <view class="msg-box">
      <view class="fff-box">
        <view class="p-box margin-top-20">
          <view class="p-title">項目名稱</view>
          <view class="p-input">
            <input placeholder="请输入項目名稱" v-model.trim="project_name" />
          </view>
        </view>
        <view class="p-box">
          <view class="p-title">擔任角色</view>
          <view class="p-input">
            <input placeholder="请输入擔任角色" v-model.trim="project_role"/>
          </view>
        </view>
        <view class="p-box">
          <view class="p-title">項目時間</view>
          <view class="p-list">
            <view class="p-item">
              <uni-datetime-picker type="date" :end="disableEndDate" v-model="start" placeholder="請選擇入學時間" @change="changeCalendar" />
            </view>
            <view class="p-c">-</view>
            <view class="p-item">
              <uni-datetime-picker type="date" :end="disableEndDate" v-model="end" placeholder="請選擇畢業時間" @change="changeCalendarEnd" />
            </view>
          </view>
        </view>
        <view class="p-box">
          <view class="p-title">項目描述</view>
          <view class="p-area">
            <textarea name="" id="" placeholder="請输入項目描述" v-model.trim="description"></textarea>
          </view>
        </view>
        <view class="p-box">
          <view class="p-title">項目業績</view>
          <view class="p-area">
            <textarea name="" id="" placeholder="請输入項目業績" v-model.trim="performance"></textarea>
          </view>
        </view>
      </view>
    </view>
    <view class="fixed-footer" @tap="handleNext()">
      <view>提交</view>
    </view>
	</view>
</template>

<script>
import navTitle from './../../boss/components/nav-title.vue';
import {userSaveProject} from '../../../utils/userApi'
export default {
	components: {navTitle},
	data() {
		return {
      disableEndDate:'',
      project_id:0,
      start:'',
      end:'',
      project_name:'',
      project_role:'',
      description:'',
      performance:'',
		}
	},
	props: {
		couponList: {}
	},
	computed: {
  },
  onShow(){
    this.disableEndDate=this.$moment().format('YYYY-MM-DD')
  },
  onLoad(options) {
    if(options.str){
      let obj=JSON.parse(options.str)
      console.log(obj)
      this.project_id=obj.id
      this.start=obj.start
      this.end=obj.end
      this.project_name=obj.project_name
      this.project_role=obj.project_role
      this.description=obj.description
      this.performance=obj.performance
    }
  },
	methods: {
    handleNext(){
      if(!this.project_name){
        uni.showToast({
          icon:'none',
          title: '請輸入項目名稱'
        })
        return
      }
      if(!this.project_role){
        uni.showToast({
          icon:'none',
          title: '请輸入擔任角色'
        })
        return
      }
      if(!this.start){
        uni.showToast({
          icon:'none',
          title: '请選擇開始時間'
        })
        return
      }
      if(!this.end){
        uni.showToast({
          icon:'none',
          title: '请選擇結束時間'
        })
        return
      }
      if(!this.description){
        uni.showToast({
          icon:'none',
          title: '请輸入項目描述'
        })
        return
      }
      if(!this.performance){
        uni.showToast({
          icon:'none',
          title: '请輸入項目績效'
        })
        return
      }
      this.submitForm()
    },
    changeCalendar(e){
      this.start=e
    },
    changeCalendarEnd(e){
      this.end=e
    },
    async submitForm(){
      let res=await userSaveProject({
        project_id:this.project_id,
        project_name:this.project_name,
        project_role:this.project_role,
        start:this.start,
        end:this.end,
        description:this.description,
        performance:this.performance,
      })
      if(res.code==1){
        uni.showToast({
          icon:'none',
          title: '添加成功'
        })
        uni.navigateBack()
      }else{
        uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
      }
    }
	}
};
</script>
<style lang="scss" scoped>
.leave_box{
  width: 100%;
  height: 100vh;
  overflow-y: scroll;
  background: #F4F6FA;
}
.msg-box{
  width: 100%;
  overflow-y: scroll;
  margin: 0 auto;
}
.fixed-footer{
  width: 100%;
  height: 50px;
  margin: 20px 0;
  view{
    width: calc(100% - 40px);
    height: 44px;
    line-height: 44px;
    text-align: center;
    background: linear-gradient( 90deg, #016CF1 0%, #0697F6 100%);
    border-radius: 8px;
    font-weight: 500;
    font-size: 15px;
    color: #FFFFFF;
    margin: 4px auto 0;
  }
}
.fff-box{
  background: #fff;
  width: calc(100% - 20px);
  border-radius: 10px;
  padding: 0 10px 20px;
  margin: 10px auto;
}
.p-title{
  font-size: 14px;
  color: #333333;
  line-height: 20px;
  padding: 15px 0 10px 0;
}
.p-list{
  display: flex;
  justify-content: center;
  align-items: center;
  .p-c{
    width: 50px;
    text-align: center;
    line-height: 50px;
  }
  .p-item{
    width: 145px;
    height: 50px;
    text-align: center;
    line-height: 50px;
    font-weight: 600;
    font-size: 16px;
    color: #333333;
    background: #F4F6FA;
    margin-bottom: 10px;
    border-radius: 8px;
  }
}
.p-input{
  width: calc(100% - 20px);
  height: 50px;
  line-height: 50px;
  border-radius: 8px;
  border: 1px solid #C2C7CC;
  color: #808080;
  font-size: 16px;
  padding: 0 10px;
  input{
    width: 100%;
    height: 100%;
  }
}
.p-area{
  width: calc(100% - 20px);
  height: 200px;
  line-height: 40px;
  border-radius: 8px;
  border: 1px solid #C2C7CC;
  color: #808080;
  font-size: 16px;
  padding:10px;
  textarea{
    width: 100%;
    height: 100%;
  }
}
.item {
  line-height: 100rpx;
  text-align: center;
}
.margin-top-20{
  margin-top: 20px;
}
</style>
